package com.tdam2011.grupo06;

import java.util.ArrayList;


import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListaAccionesSMS extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lista_acciones_sms);
        
        ListView lv = (ListView) findViewById(R.id.list);
        AccionSMSAdapter adapter = new AccionSMSAdapter(obtenerAcciones());     
        lv.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_lista_acciones_sms, menu);
        return true;
    }
    
    private ArrayList<AccionSMS> obtenerAcciones(){
    	ArrayList<AccionSMS> acciones = new ArrayList<AccionSMS>();
    	
    	acciones.add(new AccionSMS("20/09/2012 07:30", "Primer mensaje enviado.. "));
    	acciones.add(new AccionSMS("20/09/2012 07:35", "Segundo mensaje enviado.."));
    	
    	return acciones;
    }
    
    class AccionSMS{
    	String fechaHora;
    	String resumen;
    	
    	public AccionSMS (String fechaHora, String resumen){
    		this.fechaHora = fechaHora;
    		this.resumen = resumen;
    	}
    	
    	public String getFechaHora(){
    		return this.fechaHora;
    	}
    	
    	public String getResumen(){
    		return this.resumen;
    	}
    }
    
    class Holder{
    	TextView txtFechaHora, txtResumen; 
    }
    
    class AccionSMSAdapter extends BaseAdapter{

    	private ArrayList<AccionSMS> _acciones;
    	private LayoutInflater _inflater;
    	
    	public AccionSMSAdapter(ArrayList<AccionSMS> acciones){
    		_acciones = acciones;
    		_inflater = LayoutInflater.from(ListaAccionesSMS.this);
    	}
    	
		public int getCount() {
			// TODO Auto-generated method stub
			return _acciones.size();
		}

		public AccionSMS getItem(int position) {
			// TODO Auto-generated method stub
			return _acciones.get(position);
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			Holder holder = null;
			if (convertView == null) {
				convertView = _inflater.inflate(R.layout.accion_sms_item, null);
				holder = new Holder();
				
				holder.txtFechaHora = (TextView) convertView
						.findViewById(R.id.textView1);
				
				holder.txtResumen = (TextView) convertView
						.findViewById(R.id.textView2);
								
				convertView.setTag(holder);
			} else {
				holder = (Holder) convertView.getTag();
			}

			AccionSMS accion = _acciones.get(position);

			holder.txtFechaHora.setText(accion.getFechaHora());
			holder.txtResumen.setText(accion.getResumen());

			return convertView;
		}
    	
    }
}
